﻿// Study0804.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 第八章 多态 虚函数 一般函数成员

#include <iostream>
using namespace std;

class Base1
{
public:

	virtual void display() const;
};
void Base1::display() const
{
	cout << "调用Base1的Display函数" << endl;
}

class Base2 :public Base1
{
public:
	void display() const override;
};

void Base2::display() const
{
	cout << "调用Base2的Display函数" << endl;
}

class Derived :public Base2
{
public:
	void display() const override;
};

void Derived::display() const
{
	cout << "调用Derived的Display函数" << endl;
}

void fun(Base1* ptr)
{
	ptr->display();
}
int main()
{
	Base1 base1;
	Base2 base2;
	Derived der;
	fun(&base1);
	fun(&base2);
	fun(&der);
	return 0;
}


